#include "engine.h"

Renderer::Renderer() {
	script_land.load_library_xml();
	script_land.load_library_opengl();
	script_land.create_link(XLUA_parser_set_mapping,"set_map");
	script_land.create_link(XLUA_parser_get_mapping,"get_map");
	script_land.load_file( Util::create_filepath( Util::config["SYS"].stringStore["PATH"].store.sData , string("renderer.lua") ).c_str() );
	script_land.call("init");
	script_land.remove_link(string("init"));
	script_land.remove_link(string("set_map"));
	script_land.remove_link(string("get_map"));
	/* tag fn map initialization done */

	script_land.create_link(XLUA_library_new,"library_new");
	script_land.create_link(XLUA_library_get,"library_get");
	script_land.create_link(XLUA_library_set,"library_set");
	script_land.create_link(XLUA_canvas_new,"canvas_new");
	script_land.create_link(XLUA_canvas_get,"canvas_get");
	script_land.create_link(XLUA_canvas_set,"canvas_set");
	script_land.create_link(XLUA_config_new,"config_new");
	script_land.create_link(XLUA_config_get,"config_get");
	script_land.create_link(XLUA_config_set,"config_set");
	/* ready for rendering */
}

void Renderer::render(int frame) {
	DICTITER canvas_iter;
	GENOBJ_SDATAITER gds_iter;
	MAPITER mp_iter; 
	struct generic_data typeValue;
	for(canvas_iter = Util::canvas.repository.begin(); canvas_iter != Util::canvas.repository.end(); canvas_iter++) {
		gds_iter = canvas_iter->second.stringStore.find("type");
		if(gds_iter == canvas_iter->second.stringStore.end()) continue;
		typeValue = gds_iter->second;	if(typeValue.isNumber) continue; /* only string mapping to dictionary allowed */
		mp_iter  = mapping_tag_fn.find(typeValue.store.sData);
		if(mp_iter == mapping_tag_fn.end()) continue;
		script_land.call(mp_iter->second,frame);
	}
}
